/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.table;

import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import simplemetrosystem.model.Element.MetroEdge;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.Layout.GBC;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.action.CloseTabActionListener;
import simplemetrosystem.view.action.RemoveEdgeActionListener;

/**
 *
 * @author Eric Qian
 */
public class EdgeTableToolPane extends JPanel {

    public EdgeTableToolPane(InformationPane infPane, MetroEdge edge) {
        this.infPane = infPane;
        this.edge = edge;
        nameMap = NameMap.getInstance();
        loadComponent();
    }

    private void loadComponent() {
        setLayout(new GridBagLayout());

        add(getRemoveEdgeButton(), new GBC(0, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getCloseTabButton(), new GBC(1, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getSearchPane(), new GBC(2, 0).setWeight(100, 0).setFill(GBC.BOTH));
    }

    private JButton getRemoveEdgeButton() {
        if (RemoveEdgeButton == null) {
            RemoveEdgeButton = new JButton();
            RemoveEdgeButton.setText(nameMap.getName("Remove Edge"));
            RemoveEdgeButton.setToolTipText(nameMap.getName("Remove Edge"));
            RemoveEdgeButton.addActionListener(new RemoveEdgeActionListener(infPane.getFrame(), edge));
        }
        return RemoveEdgeButton;
    }

    private JButton getCloseTabButton() {
        if (closeTabButton == null) {
            closeTabButton = new JButton();
            closeTabButton.setText(nameMap.getName("Close Tab"));
            closeTabButton.setToolTipText("Close Tab");
            closeTabButton.addActionListener(new CloseTabActionListener(infPane));
        }
        return closeTabButton;
    }

    private SearchPane getSearchPane() {
        if (searchPane == null) {
            searchPane = new SearchPane(infPane);
        }
        return searchPane;
    }
    private InformationPane infPane;
    private NameMap nameMap;
    private MetroEdge edge;
    private JButton RemoveEdgeButton;
    private JButton closeTabButton;
    private SearchPane searchPane;
}
